feat(postgres): add Postgres.js tracing - #10125
Conversation
Overall package sizeSelf size: 8.89 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.4.0 | 127.33 kB | 447.04 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: c12c04a | Docs | View more details | Give us feedback! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #10125 +/- ##
========================================
Coverage 98.69% 98.70%
========================================
Files 1008 1012 +4
Lines 158514 158926 +412
Branches 74 74
========================================
+ Hits 156448 156860 +412
Misses 2066 2066
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
BenchmarksBenchmark execution time: 2026-09-10 11:09:00 Comparing candidate commit c12c04a in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 2299 metrics, 14 unstable metrics.
|
8dcf731 to
51a4551
Compare
| tracer.use('pg', { truncate: 5000 }); | ||
| tracer.use('pino'); | ||
| tracer.use('postgres'); | ||
| tracer.use('postgres', { service: 'postgres-service' }); |
There was a problem hiding this comment.
we are moving away from allowing configurable per integration service name, can this be removed along with the optional configuration
There was a problem hiding this comment.
I believe doing this only for some is not ideal. Otherwise it is likely confusing for customers. I believe it would also require special handling to prevent it (I believe it is a generic functionality)
51a4551 to
6d2af20
Compare
6d2af20 to
3eac035
Compare
Postgres.js keeps lazy queries and connection handlers in module-local closures. A Query can also settle after cursor replacement or retry. Instrument the source-owned dispatch and settlement boundaries to keep one span across queues, cursors, retries, and cancellations. Fixes: #2644
Postgres.js retains host and port values when a socket path is active, which made Unix-socket spans report a TCP endpoint that was not used.
Postgres.js uses whole-program transforms that do not share the generic transform contract.
3eac035 to
c12c04a
Compare
|
the sentry implementation may be useful to peek at -> https://github.com/getsentry/sentry-javascript/blob/develop/packages/server-utils/src/integrations/postgresjs.ts This would be an awesome feature!! |
What does this PR do?
Adds automatic tracing for Postgres.js 3.x in CommonJS and ESM.
It starts spans when lazy queries enter a connection handler and finishes them at final Query settlement. Query identity and public methods remain unchanged.
The plugin reports compiled SQL resources, PostgreSQL database and endpoint tags, schema-aware names, peer service, truncation, and errors.
Motivation
Postgres.js is not currently instrumented, so applications using it do not emit database spans.
Its connection handlers and Query settlement functions remain in module-local closures, which makes runtime export wrapping incomplete.
Additional Notes
The real PostgreSQL matrix runs against 3.0.0 and 3.4.9 in CommonJS and ESM. It covers:
Postgres.js 1.x is excluded because it has a different internal architecture.
This does not add DBM propagation, AppSec query blocking, or a separate pool span.
Refs #2644